<template xmlns="http://www.w3.org/1999/html">
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="110px"
    >
      <el-form-item label="用户ID" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入用户ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户账号" prop="account">
        <el-input
          v-model="queryParams.account"
          placeholder="请输入用户账号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="充值单号" prop="rechargeSn">
        <el-input
          v-model="queryParams.rechargeSn"
          placeholder="请输入充值单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="充值日期" prop="queryDate">
        <el-date-picker
          v-model="queryParams.queryDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择日期"
          @keyup.enter.native="handleQuery"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="审核状态" prop="orderStatus">
        <el-select
          v-model="queryParams.orderStatus"
          placeholder="请选择审核状态"
          clearable
          size="small"
          style="width: 240px"
        >
          <el-option
            v-for="item in orderStatusOptions"
            :key="item.dictValue"
            :label="item.dictLabel"
            :value="item.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="支付方式" prop="payType">
        <el-select
          v-model="queryParams.payType"
          placeholder="请选择支付方式"
          clearable
          size="small"
          style="width: 240px"
        >
          <el-option
            v-for="item in payTypeOptions"
            :key="item.dictValue"
            :label="item.dictLabel"
            :value="item.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="cyan"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索
        </el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置
        </el-button>
      </el-form-item>
    </el-form>

    <el-table
      v-loading="loading"
      :data="userRechargeList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column label="序号" align="center" prop="rechargeId" />
      <el-table-column label="充值单号" align="center" prop="rechargeSn" />
      <el-table-column label="交易流水号(线上支付)" align="center" prop="orderCd" />
      <el-table-column
        label="金额类型"
        align="center"
        prop="amtType"
        :formatter="amtTypeFormat"
      >
      </el-table-column>
      <el-table-column label="充值金额" align="center" prop="orderAmt" />
      <el-table-column label="充值账号" align="center">
        <template slot-scope="scope">
          用户ID：{{ scope.row.userId }}<br />
          账号：{{ scope.row.account }}
        </template>
      </el-table-column>
      <el-table-column label="申请时间" align="center" prop="createTime" />
      <el-table-column label="审核时间" align="center" prop="payTime" />
      <el-table-column label="转账截图" align="center">
        <template slot-scope="scope">
          <el-image
            style="width: 100px; height: 140px"
            :src="requestUrl + scope.row.submitImage"
            :preview-src-list="scope.row.submitImageList"
          >
          </el-image>
        </template>
      </el-table-column>
      <el-table-column label="支付方式" align="center" prop="payType" :formatter="payTypeFormat" />
      <el-table-column label="状态" align="center" prop="orderStatus" :formatter="orderStatusFormat"/>
      <el-table-column label="团队" align="center" prop="teamId"/>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-check"
            v-show="scope.row.orderStatus == 0"
            @click="auditRecharge(scope.row, 1)"
            v-hasPermi="['admin:userRecharge:edit']"
            >通过
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-close"
            v-show="scope.row.orderStatus == 0"
            @click="auditRecharge(scope.row, -1)"
            v-hasPermi="['admin:userRecharge:edit']"
            >拒绝
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { getUserRechargePage, audit } from "@/api/admin/userRecharge";

export default {
  name: "UserRechargeManage",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 任务详情表格数据
      userRechargeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      type: "all",
      form: {},
      //用于回显字典类型
      amtTypeOptions: [],
      requestUrl: this.$img.requestUrl,
      orderStatusOptions: [
        {
          dictValue: 0,
          dictLabel: "待审核",
        },
        {
          dictValue: 1,
          dictLabel: "审核通过",
        },
        {
          dictValue: -1,
          dictLabel: "审核拒绝",
        },
      ],
      payTypeOptions: [
        {
          dictValue: 1,
          dictLabel: "线下充值",
        },
        {
          dictValue: 2,
          dictLabel: "银行卡支付",
        }
      ],
    };
  },
  created() {
    this.getList();
    //字典类型
    this.getDicts("amt_type").then((response) => {
      this.amtTypeOptions = response.data;
    });
  },
  methods: {
    // 登录状态字典翻译
    amtTypeFormat(row, column) {
      return this.selectDictLabel(this.amtTypeOptions, row.amtType);
    },
    payTypeFormat(row, column) {
      return this.selectDictLabel(this.payTypeOptions, row.payType);
    },
    orderStatusFormat(row, column) {
      return this.selectDictLabel(this.orderStatusOptions, row.orderStatus);
    },
    getList() {
      this.loading = true;
      getUserRechargePage(this.queryParams).then((response) => {
        this.userRechargeList = response.rows;
        this.total = response.total;
        this.loading = false;
        this.userRechargeList.forEach((item) => {
          let submitImageList = [];
          submitImageList.push(this.requestUrl + item.submitImage);
          item.submitImageList = submitImageList;
        });
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    auditRecharge(row, orderStatus) {
      let text = "";
      if (orderStatus == 1) {
        text = "是否确认已打款";
      } else if (orderStatus == 2) {
        text = "是否确认拒绝打款";
      }
      let submitForm = { rechargeId: row.rechargeId, orderStatus: orderStatus };
      this.$confirm(text, "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return audit(submitForm);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("审核成功");
        })
        .catch(function () {});
    },
  },
};
</script>
<style>
.sudoku_row {
  display: flex;
  align-items: center;
  width: 100%;
  flex-wrap: wrap;
}

.sudoku_item {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  width: 25%;
  padding-top: 10px;
  padding-bottom: 10px;
}

.opacity {
  opacity: 0.4;
  background: #e5e5e5;
}

.sudoku_item img {
  margin-bottom: 3px;
  display: block;
}
</style>
